<extend name="Common:base"/>
<block name="head">
  <style>
    .el-tabs__header{
      border-top:2px solid #ea4b4b;
      border-bottom: 1px solid #c51f1f;
    }
    .el-dialog .el-tabs__header{
      border-top:none;
    }
    .el-tabs--border-card .el-tabs__item{
      border-left: none;
    }
    .el-tabs--border-card .el-tabs__item.is-active {
      background-color: #fff;
      border-right-color: #d3dce6;
      background: #544b8f;
      color: #fff;
    }
    .el-tabs--border-card .el-tabs__header {
      background-color: #fff;
      margin: 0;
    }
    .container > .wrapp > .a > .el-row {
      margin-bottom: 6px;
    }
    .el-tabs--border-card .el-tabs__content{
      padding:0 9px 5px 9px;
    }
    .el-card, .el-menu--horizontal .el-submenu>.el-menu, .el-tabs--border-card{
      box-shadow: none;
    }
    .el-tabs--border-card{
      border: none;
    }
    .el-tabs__item{
    	font-family: Microsoft YaHei;
    	color:#0d0f10;
    	font-size: 14px;
    }
    .el-dialog__body{
      color: rgb(72, 87, 106);
      font-size: 14px;
      /*padding: 30px 20px;*/
      padding: 30px 20px 6px 20px;
    }
  </style>
</block>
<block name="body">
	<div id="app" class="container">
		<div class="wrapp" v-show="show" style="display:none;">
			<div class="a">
				<el-row>
        	<el-col :span="24">
          	<el-form :inline="true" ref="searchForm" :model="searchForm">
          		<el-form-item v-show="departName=='总部'">
	              <el-select size="small" style="width:150px;" v-model="searchForm.belongs_department" clearable filterable allow-create placeholder="所属部门">
                  <el-option v-for="department in belongsDepartment" :label="department.name" :value="department.name"></el-option>
	              </el-select>
			  		  </el-form-item>
			  		  
			  		  <el-form-item>
	              <el-select size="small" style="width:150px;" v-model="searchForm.type" clearable filterable allow-create placeholder="所属类别">
                  <el-option v-for="(value,key) in type" :label="value" :value="value"></el-option>
	              </el-select>
			  		  </el-form-item>

			  		  <el-form-item prop="name" style="width:150px">
			  		    <el-input v-model="searchForm.name" size="small" placeholder="用品名称"></el-input>
			  		  </el-form-item>

	            <el-form-item>
	              <el-tooltip content="填写或者选择好筛选条件后点击此按钮" placement="bottom-start">
	                <el-button type="info" size="small" icon="search" @click="loadDatalist">查询</el-button>
	              </el-tooltip> 
	            </el-form-item>
             
              <el-form-item>
	              <el-tooltip content="清空搜索框并刷新表格数据" placement="bottom-start">
	                <el-button size="small" @click="resetBack">重置</el-button>
	              </el-tooltip>
              </el-form-item>

	            <el-form-item>
	              <el-tooltip content="点击刷新当前页面" placement="right">
	                <el-button @click="refresh" size="small" type="danger">刷新</el-button>
	              </el-tooltip>
	            </el-form-item>
            </el-form>
          </el-col>
			  </el-row>

			  <el-row>
        	<el-col :span="24">
	          <el-table v-loading="dataLoad" :data="dataList"
                @selection-change="handleChange"
	              element-loading-text="{:L('DATA_LOGIN')}"
	              empty-text="暂无数据！"
	              highlight-current-row ref="select" border>
              <el-table-column type="selection" width="55"></el-table-column>

			  	    <el-table-column label="{:L('INDEX')}" type="index" width="65" >
			  	    </el-table-column>
			  	    
			  	    <el-table-column  align="center" prop="belongs_department" label="部门">
	            </el-table-column>

	            <el-table-column  align="center" prop="name" label="用品名称">
	            </el-table-column>

			  	    <el-table-column  align="center" prop="type" label="所属类别">
			  	    </el-table-column>

              <el-table-column  align="center" prop="unit" label="单位">
              </el-table-column>

              <el-table-column  align="center" prop="specification" label="规格">
              </el-table-column>
              
              <!--<el-table-column  align="center" prop="price" label="单价">
              </el-table-column>-->

              <el-table-column  align="center" prop="attributes" label="物品属性">
              	<template scope="scope">
				          {{ getType(scope.row.attributes, 'attributes') }}
				        </template>
              </el-table-column>
              <el-table-column label="是否启用" :context="_self" align="center" prop="status">
					      <template scope="scope">
  							<div>
  						        <el-switch
  								  v-model="scope.row.switch"
  								  on-color="#13ce66"
  								  off-color="#ff4949" 
  								  @change="switchHandle(scope.$index, scope.row)">
  								</el-switch>
  							</div>
                         </template>
					    </el-table-column>
	          </el-table>
          </el-col>
			  </el-row>

			  <el-row>
			  	<el-col :span="12">
			      <div class="grid-content bg-purple">
              <span class="wrapper">
                <el-tooltip content="至少选择一条信息再点击删除" placement="bottom-start">
                  <el-button size="small" @click="handleDeletes" type="danger">删除</el-button>
                </el-tooltip>
                <el-tooltip content="点击新增一个录入资料申请" placement="right">
                  <el-button size="small" @click="openDialog('add')" type="primary">录入资料</el-button>
                </el-tooltip>
              </span>
			      </div>
			    </el-col>
			  	<el-col :span="12" >
			      <div class="grid-content bg-purple-light pull-right">
			        <!-- page -->
			        <include file="Common:_pagination" />
			        <!-- / page -->
			      </div>
			    </el-col>
			  </el-row>
			</div>
			<div class="dialogWrapper" v-show="show" style="display: none">
			  <!-- 新增 -->
			  <include file="_add" />
		    <!-- / 新增 -->
			</div>
		</div>
	</div>
</block>
<block name="scripts">
<script>
	window.defaultOption.setDatas({
		multipleSelection: [],
		dialogLabelWidth:"120px",
    dataList:[],
    type:{:json_encode($type)},
    attributes:{:json_encode($attributes)},
    belongsDepartment:{:json_encode($belongsDepartment)},
    departName:{:json_encode($departName)},
    statusForm:{
       id:'',
       status:'1',
    },
    addRules:{
			name:[
				{pattern:/^([^\s]){1,10}$/,message:'不超过10个汉字！不能使用空格',required: true},
			],
			type:[
      {required: true, message: '请输入物品类别', trigger: 'blur'},
			],
			unit:[
      {pattern:/^([^\s]){1,4}$/,message:'不超过4个汉字！不能使用空格',required: true},
			],
			specification:[
      {pattern:/^([^\s]){1,42}$/,message:'不超过42个汉字！不能使用空格',required: true},
			],
			
			attributes:[
      {required: true, message: '请选择物品属性'},
			]
		},
	}).setForm('add',{
    name:"",
    type:"",
    unit:"",
    specification:"",
    attributes:"",
    belongs_department:'',
    info_status:"1",
  },true).setForm('search',{
  	belongs_department:{:json_encode($departName)},
		type:"",
    name:'',
	}).setMethod('resetBack',function(){
    window.location.href="{:U('index')}";
  }).setMethod('getType', function(type, field){
 		return this[field][type];
  }).setMethod('handleChange', function(val){
	  this.multipleSelection = val; //点击勾选用这个
		//点击选中用这个 开始
		/*this.deleteArrAllItem('multipleSelection');
		this.multipleSelection.push(val) ;*/
		//点击选中用这个 结束
	    
	}).setMethod('beforeList',function(dataList){
		var vmThis = this;
		dataList.forEach(function(currentValue, index){
           // currentValue['type']     = parseInt(currentValue['type']);
			//currentValue['typeText'] = vmThis.typeList[currentValue['type']];
			// currentValue['zone']     = vmThis.zoneList[currentValue['zone_id']];
  		    currentValue['switch']   = currentValue.status==1?true:false;
            currentValue.status = parseInt(currentValue.status);
		})
		return dataList;

	}).setMethod('switchHandle',function(index,row){
	    row.status=row.switch?'0':'1';
	    this.initObject(this.statusForm, row);
	    this.statusIndex=index;
	    var vmThis =this;
	    this.$http.post(page.editFormUrl,this.statusForm).then(function(response){
	    	
	    }).catch(function(response){
	    	vmThis.$message({
	    		message:'状态更改失败',
	    		type:'error'
	    	});
	    	vmThis.dataList[vmThis.statusIndex].switch = !vmThis.dataList[vmThis.statusIndex].switch;
	    });
    }).setMethod("handleDeletes", function(url){
	  if(this.multipleSelection.length != 1){
		  this.$message.error('请选择一条信息');
		  return false;
	  }else{
		  if (!arguments[2]) {
			  url= this.page.deleteUrl;
		  }
		  var selectedIds = new Array();
		  for(var i=0; i<this.multipleSelection.length; i++){
			  selectedIds[i] = this.multipleSelection[i].id;
		  }
		  var vmThis = this;
		  this.$confirm('确定删除?', '提示', {
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			  type: 'warning'
		  }).then(function(){
			  vmThis.$http.post(url, {ids:selectedIds}).then(function(response){
				  vmThis.$message({
					  type: 'success',
					  message: '删除成功!'
				  });
				  vmThis.loadDatalist();
			  }, function(response){
				  vmThis.$message({
					  type: 'error',
					  message: '该用品资料已在使用中，请不要删除！'
				  });
			  })
		  }).catch(function() {
			  vmThis.$message({
				  type: 'info',
				  message: '已取消操作'
			  });
		  });
	  }

  });
</script>
</block>